<?php 
	class CategoryAction extends CommonAction{
		public function index(){
			$cate=M('cate')->order('sort')->select();
			import('Class.Category',APP_PATH);
			$this->cate=Category::unlimitedForLevel($cate);
			$this->display();
		}

		//添加分类视图
		public function cate(){
			$this->pid=$_GET['pid']?$_GET['pid']:0;
			$this->display();
		}

		//添加分类表单处理
		public function addCate(){
			$cate=$_POST;
			if(M('cate')->add($cate)){
				$this->success('添加成功!',U(GROUP_NAME.'/Category/index'));
			}else{
				$this->error('添加失败!');
			}
		}

		//删除分类
		public function delCate(){
			$id=$_GET['id'];
			if(M('cate')->delete($id))$this->success('删除成功!',U(GROUP_NAME.'/Category/index'));
			else $this->error('删除失败!');
		}

		//修改排序
		public function sortCate(){
			$index=0;
			foreach ($_POST as $key => $value) {
				$where['id']=$key;
				$data['sort']=(int)$value;
				M('cate')->where($where)->save($data);
				$index++;
			}
			if($index)$this->success('排序成功!',U(GROUP_NAME.'/Category/index'));
			else $this->error('排序失败!');
		}
	}